﻿using System;
using System.Windows.Media.Animation;

namespace CodeGears.WorkItemTracking.ChartingDashboard
{
    public partial class MainView
    {
        private const string AfterLogInAnimation = "AfterLogIn";

        public MainView()
        {
            InitializeComponent();
            grid.Opacity = 0;

            var model = new MainViewModel(this);
            DataContext = model;
            model.StartLoginTimer();
        }

        public void StartAnimation()
        {
            Dispatcher.Invoke(new Action(() =>
                                             {

                                                 var storyboard = this.Resources[AfterLogInAnimation] as Storyboard;
                                                 if (storyboard != null)
                                                     storyboard.Begin();
                                             }));
        }

        public void AddChart(ChartView chartView)
        {
            Dispatcher.Invoke(new Action(() => LayoutRoot.Children.Add(chartView)));
        }

        public void ShowLoginBox()
        {
            Dispatcher.Invoke(new Action(() => LoginPopup.IsOpen = true));
        }

        public void HideLoginBox()
        {
            Dispatcher.Invoke(new Action(() => LoginPopup.IsOpen = false));
        }
    }
}